﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;

namespace TAM_SPORT
{
    public partial class CustomerRemindHist : Form
    {
        public CustomerRemindHist()
        {
            InitializeComponent();
        }

        public CustomerRemindHist(int id)
        {
            InitializeComponent();
            onload(id);
        }

        private void onload(int id)
        {
            PurchaseDao dao = new PurchaseDao();
            DataRow row = dao.getCustomerHist(id);
            if (row != null)
            {
                txtName.Text = row["NAME"].ToString();
                rtbNote.Text = row["NOTE"].ToString();
                loadImageCapture(row["PICTURE"].ToString());
                txtMonth.Text = row["TOTAL_MONTH"].ToString();
            }
            CustomerDao cusDao = new CustomerDao();
            DataTable table = cusDao.getremindHist(id);
            dtgCustomers.Rows.Clear();
            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow row1 in table.Rows)
                {
                    int i = dtgCustomers.Rows.Add();
                    dtgCustomers.Rows[i].Cells[0].Value = i + 1;
                    dtgCustomers.Rows[i].Cells[1].Value = DateTime.Parse(row1["CREATE_AT"].ToString()).ToString("dd/MM/yyyy");
                    dtgCustomers.Rows[i].Cells[2].Value = row1["FULL_NAME"].ToString();
                    if (i % 2 == 1)
                    {
                        dtgCustomers.Rows[i].DefaultCellStyle.BackColor = Color.LightCyan;
                    }
                }
            }
        }
        public void loadImageCapture(string filename)
        {
            string path = filename;
            if (!String.IsNullOrEmpty(path))
            {
                try
                {
                    ptbImage.LoadAsync(path);
                    ptbImage.SizeMode = PictureBoxSizeMode.Zoom;
                    ptbImage.Text = filename;
                }
                catch (Exception ex)
                {
                    ptbImage.Image = null;
                    Console.WriteLine(ex);
                }
            }
            else
            {
                ptbImage.Image = null;
            }
        }

    }
}
